﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using Model;

namespace BLL
{
    public class HouseManage
    {
        public static House AddHouse(House house)
        {
            return HouseService.AddHouse(house);
        }

        public static List<House> GetAllHouses()
        {
            return HouseService.GetAllHouses();
        }

        public static List<House> GetLatestHouses(int p)
        {
            return HouseService.GetLatestHouses(p);
        }

        public static House GetHouseById(int hId)
        {
            return HouseService.GetHouseById(hId);
        }

        public static bool ChangeStatus(int hId, int statusCodeName)
        {
            House house = HouseService.GetHouseById(hId);
            if (house == null)
                return false;
            house.StatusCodeId = statusCodeName;
            if (HouseService.UpdateHouse(house) != null)
                return true;
            return false;
            
        }

        public static void DeleteHouse(int hId)
        {
            HouseService.DeleteHouse(hId);
        }

        public static List<House> GetAllHouses(int UserId)
        {
            return HouseService.GetAllHouses(UserId);
        }

        public static List<House> GetHousesByStatus(int UserId, int StatusCodeId)
        {
            return HouseService.GetAllHouses(UserId, StatusCodeId);
        }

        public static List<House> GetLatestHouses(int UserId, int count)
        {
            return HouseService.GetLatestHouses(UserId, count);
        }

        public static List<House> GetHousesNotChecked()
        {
            return HouseService.GetHousesNotChecked();
        }

        public static List<House> GetHousesChecked()
        {
            return HouseService.GetHousesChecked();
        }

        public static bool Checked(int HouseId, int check)
        {
            House house = HouseService.GetHouseById(HouseId);
            house.IsChecked = check;
            if (HouseService.UpdateHouse(house) != null)
                return true;
            return false;
        }

        public static void Rating(int id, int rate)
        {
            if (!HouseService.HasId(id))
                return;

            House house = GetHouseById(id);
            house.Rating = rate;
            HouseService.UpdateHouse(house);
        }

        public static void AdminReview(int id, string p)
        {
            if (!HouseService.HasId(id))
                return;
            
            House house = GetHouseById(id);
            house.AdminReview = p;
            HouseService.UpdateHouse(house);
        }

        public static void Recommend(int id, bool check)
        {
            if (!HouseService.HasId(id))
                return;

            House house = GetHouseById(id);
            house.IsRecommended = Convert.ToInt32(check);
            HouseService.UpdateHouse(house);
        }

        public static List<House> GetHousesChecked(int UserId, int p)
        {
            throw new NotImplementedException();
        }

        public static List<House> GetHousesChecked(int UserId)
        {
            return HouseService.GetHousesChecked(UserId);
        }

        public static List<House> GetHousesNotChecked(int UserId)
        {
            return HouseService.GetHousesNotChecked(UserId);
        }
    }
}
